﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.View == "undefined") Axis.View = {};
if (typeof Axis.View.CloundTags == "undefined") Axis.View.CloundTags = {};

Axis.View.CloundTags.List = {
    Init: function () {
        this.Paging.Init();
    },
    Paging: {
        isFirstPaging: true,
        Init: function () {
            var thisObj = this;
            thisObj.GetData(1, true);
        },
        GetData: function (pPageNumber, bmn) {
            var objThis = this;
            // var tagID = $.GetURL("ID") || "";

            $.Ajax({
                type: "POST",
                url: '../TagCloud/Service/ClounbTagService.asmx/GetListNews',
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{' + $.string.Format('"page":{0},"rows":{1},"tagID":{2}', pPageNumber, 5, tagID) + '}',
                success: function (pData) {
                    if (pData !== null)
                        if (pData.d !== null) {
                            var data = eval("(" + pData.d + ")");
                            Axis.View.CloundTags.List.ShowNewsList(data);
                            if (bmn) {
                                $("#paging").jpaging({
                                    all_items_num: data.total,
                                    items_on_page: data.records,
                                    callback: function (a, b, c) {
                                        objThis.GetData(a);
                                    }
                                });
                            }
                        }
                }
            });
        }
    },

    ShowNewsList: function (data) {
        var htmlContent = "";
        var pattern = "<li>"
            + "<div class='newsImage'><img class='imgNews' src='{0}' /></div>"
            + "<div class='newsPanel'>"
                + "<div>"
                    + "<h1 class='SEOH1'> <a href='{4}' class='newsTitle'>{1}</a></h1>"
                + "</div>"
                + "<div class='newsDateTime'>(Cập nhật {2})</div>"
                + "<div class='newsDescription'>{3}....</div>"
                + "<div><a href='{4}' class='newsMore'>Chi tiết</a></div>"
            + "</div>"
        + "</li>";
        $.each(data.list, function (index, Item) {
            var _date = $.CFormat.FormatDateSerializer(Item.WritenDate);
            var link = ShowDetail(Item.ID, Item.Type,Item.Title);
            htmlContent += $.string.Format(pattern, Item.ThumbnailImage, Item.Title, _date, Item.Summary, link);
        });
        $(".news_list_content").html(htmlContent);
    }
};
$(function () {
    Axis.View.CloundTags.List.Init();
});
function ShowDetail(id, type, Title) {
    var linkTitle = $.ReplacePoint(Title);
    if (Title == '')
        Title = '1';
    if (type == "0")
        return $.string.Format("../Project/{0}#{1}", id, linkTitle);
    else if (type == "1")
        return $.string.Format("../Research/{0}#{1}", id, linkTitle);
    else
        return $.string.Format("../News/{0}#{1}", id, linkTitle);

}